package com.example.gps_android_test;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.Toast;

public class SampleGPS extends Activity {

	
	private LocationManager locationManager;

	private LocationListener locationListener;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//---use the LocationManager class to obtain GPS locations---

		locationManager = (LocationManager)

		getSystemService(Context.LOCATION_SERVICE);

		locationListener = new MyLocationListener();

		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
	}
		
		private class MyLocationListener implements LocationListener
		{

			@Override
			public void onLocationChanged(Location loc) 
			{
	
				if (loc != null) 
				{
		
				Toast.makeText(getBaseContext(),
		
				"Localisation actuelle :n Lat: " + loc.getLatitude() +
		
				"  Lng: " + loc.getLongitude(),
		
				Toast.LENGTH_SHORT).show();
		
				}

			}

			@Override
			public void onProviderDisabled(String provider) 
			{
	
			// TODO Auto-generated method stub
	
			}
	
			@Override
			public void onProviderEnabled(String provider) 
			{
	
			// TODO Auto-generated method stub
	
			}
	
			@Override
			public void onStatusChanged(String provider, int status,Bundle extras) 
			{
	
			// TODO Auto-generated method stub
	
			}
		}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
